<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>

	<meta charset="UTF-8">
	<title>分类管理</title>
	<link rel="stylesheet" href="../static/css/admin.css">
	<link rel="stylesheet" href="../static/css/bootstrap.css"/>
</head>

<style type="text/css">
	*{
		margin: 0;
		padding: 0;
	}
</style>
<body>
<div class="contain">
	<jsp:include page="header.jsp"></jsp:include>
	<div class="text-right"><a class="btn btn-warning" href="category_add.jsp">添加分类</a></div>
	<br>
		<div id="right_content">

			<table class="table table-bordered table-hover"
			id="listtable">

				<tr>
					<th width="20%">ID</th>
					<th width="20%">分类名字</th>
					<th width="20%">父分类ID</th>
					<th width="20%">创建时间</th>
					<th width="20%">分类状态</th>
					<th width="20%">操作</th>
				</tr>
			</table>

			<br>
			<jsp:include page="/page.jsp">
				<jsp:param value="/admin/order_list" name="url"/>
				<jsp:param value="&status=${status}" name="param"/>
			</jsp:include>
			<br>
		</div>
	</div>
</div>
<script src="../static/ku/jQuery/jquery.min.js"></script>
<script type="text/javascript">
	getList();
	function getList() {
		$.get("/novel/category", {}, function (data) {
			for (var i = 0; i < data.length; i++) {
				var tr = "<tr>" +
						"<td>" + data[i].id + "</td>" +
						"<td>" + data[i].categoryName + "</td>" +
						"<td>" + data[i].parentId + "</td>" +
						"<td>" + data[i].createTime + "</td>" +
						"<td>" + data[i].status + "</td>" +
						"<td>" +
						"<a class='btn btn-danger' href='javascript:void(0);' onclick='deleteCategory(" + data[i].id + ")'>删除</a>" +
						"</td>" +"</tr>";
				$("#listtable").append(tr);
			}
		})
	}
	function deleteCategory(id) {
		if (confirm("确定要删除这个分类吗？")) {
			$.ajax({
				url: '/novel/category/' + id,
				type: 'DELETE',
				success: function (response) {
					if (response === true) {
						alert("删除成功");
						// 刷新页面或执行其他操作
						location.reload();
					} else {
						alert("删除失败");
					}
				},
				error: function (error) {
					console.error('Error:', error);
					alert("删除失败");
				}
			});
		}
	}
</script>
</body>
</html>
